package com.bruan.d1_io;

import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;

public class FileReaderTest1 {
    public static void main(String[] args) {
        soutFileByOneChar("file-io-app\\bruan.txt");
        soutFileByMulChar("file-io-app\\bruan.txt");

    }
    public static void soutFileByOneChar(String filePath){
        try( Reader fr = new FileReader(filePath);
        ) {
            //读取文件内容
            int len;
            while ((len = fr.read())!=-1){
                System.out.print((char)len);
            }

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    public static void soutFileByMulChar(String filePath){
        try( Reader fr = new FileReader(filePath);
        ) {
            //读取文件内容
            int len;
            char[] buffer = new char[1024];
            while ((len = fr.read(buffer))!=-1){
                System.out.print(new String(buffer,0,len));
            }

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
